<<<<<<< .mine
﻿









/////branchcombo
//(function ($) { 
//    function getBranchBindValueFieldName(target){
//        var opts = $(target).data("branchcombo");
//        if(opts){
//            return opts.bindValueField;
//        }else{
//            return undefined;
//        }
//    }

//    function showRowData(target, rowData){
//        target.combo("setValue",rowData.id);
//        target.combo("setText",rowData.name);
//        branchTextChange(target, rowData);
//    }

//    function branchTextChange(target, rowData ){
//        var opts = $(target).data("branchcombo");
//        if(opts.onTextChange){
//            opts.onTextChange.call(target,rowData.name);
//        }
//        if(opts.onValueChange){
//         opts.onValueChange.call(target,rowData.id);
//        }
//    }

//$.fn.branchcombo=function(options,param){
//    if (typeof options == "string") {
//        return $.fn.branchcombo.methods[options](this, param);
//    }
//    options = options || {};
//    return this.each(function () {
//        var opts;
//        var state= $(this).data("branchcombo");
//        if (state) {
//            opts = $.extend(state, options);
//         } else {
//            var parentCombo=$(this);
//            opts = $.extend({},$.fn.branchcombo.defaults, $.fn.branchcombo.parseOptions(this), options);
//            var codeJson =initDepart();
//            var codeTreeID=$(this).attr("id")+"_departtree";
//            if ($("#"+codeTreeID) != undefined && $("#"+codeTreeID).length!=0) {
//                $("#"+codeTreeID).empty();
//                $("#"+codeTreeID).remove();
//            }
//             $(this).combo({editable:false});//禁用手工输入
//            $(this).combo("panel").panel({
//                width:400,
//                content:"<table id='"+codeTreeID+"'></table>"
//            });
//            
//            var codetreegrid= $("#"+codeTreeID);
//            codetreegrid.treegrid({
//                idField: "id",
//                treeField: "code",
//                height: parentCombo.combo("options").panelHeight,
//                rownumbers: true,
//                columns: [[
//                    { field: "id", title: 'id', hidden: true },
//                    { field: 'code', title: "部门编号", width: 200 },
//                    { field: "name", title: "部门名称", width: 300 }
//                ]],
//                fitColumns:true,
//                singleSelect:true,
//                onClickRow: function (rowData) {
//                    showRowData(parentCombo, rowData);
//                },
//                onDblClickRow:function(rowData){
//                    showRowData(parentCombo, rowData);
//                    parentCombo.combo("hidePanel");
//                }
//            });
//            codetreegrid.treegrid("loadData",codeJson);
//            opts.treegrid = codetreegrid;
//        }
//        if(opts.bindValueField)
//        {
//            if(opts.bindValueField!="" && opts.bindValueField.substring(0,1)!="#"){
//                opts.bindValueField = "#"+ opts.bindValueField;
//            }
//        }
//        $(this).data("branchcombo",opts);
//    });
//};
//    $.fn.branchcombo.defaults=$.extend({},$.fn.validatebox.defaults,
//    {bindValueField: "",onTextChange: function(newText){
//            var valueField = getBranchBindValueFieldName(this);
//            if(valueField) {
//                $(valueField).val(newText);
//            }
//        },
//        onValueChange:function(newValue){
//        
//        }
//        });

//    $.fn.branchcombo.parseOptions = function (target) {
//        var t = $(target);
//        return $.extend({},{},$.fn.validatebox.parseOptions(target), $.fn.combo.parseOptions(target), {
//            bindValueField: (t.attr("bindValueField") || undefined)
//        });
//    };

//    $.fn.branchcombo.methods = {
//        setValue: function () { return null; },
//        getBindField: function(jq){ return getBranchBindValueFieldName(jq);},
//        treegrid:function(jq){
//            return $(jq[0]).data("branchcombo").treegrid;
//        },
//        getRoot:function(jq,nodeid){
//            var treegrid = $(jq).branchcombo("treegrid");
//            var rootNode = treegrid.treegrid("getParent", nodeid);
//            var rootNode1 = null;
//            while (rootNode != null) {
//                rootNode1 = rootNode;
//                rootNode = treegrid.treegrid("getParent", rootNode.id);
//            }
//            return rootNode1;
//        }
//    };
//})(jQuery);

/////orgcombotree
//(function ($) {
//function initOrg(includeMember){
//    var $data = dataService.getData(SysConstant.TaskGuid.OrgInfo, Constant.SysDataGuid.OrgInfo.CompanyListGuid, Constant.Identify.CompanyList);
//    var $xml = utility.xml.convertXmlStringToDoc($data);
//    var $list=$xml.find("OUDataInfo");
////    var orgList=[];
////    $.each($list,function(i,n){
////    var $comlist = $xml.find("OUDataInfo");
////    })
////    

//    return pushChildList($list,includeMember);
//}
//function pushChildList($list,includeMember) {
//    var $departJson = [];
//    if (!$list.length > 0)
//        return;
//    $list.each(function (i, n) {
//        var $childData = dataService.getData(SysConstant.TaskGuid.OrgInfo, $(n).attr("GUID"), Constant.Identify.BranchList);
//        var $childXml = utility.xml.convertXmlStringToDoc($childData);
//        var $childList = $childXml.find("OUDataInfo");
//        var deptInfo = $(n).attr("Name");
//        $departJson.push({
//            "id": $(n).attr("GUID"),
//            "text": deptInfo, 
//            "attributes":[{nodeType: $(n).attr("OUType")}],
//            "state": $childList.length > 0 ? "closed" : undefined,
//            "children": $childList.length > 0 ? pushChildList($childList,includeMember) : includeMember?pushMember($(n).attr("GUID")):undefined
//        });
//    });
//    return $departJson;
//}

//function pushMember(branchGuid)
//{
//        var $childData = dataService.getData(SysConstant.TaskGuid.OrgInfo, branchGuid, Constant.Identify.BranchMemberList);
//        var $childXml = utility.xml.convertXmlStringToDoc($childData);
//        var $childList = $childXml.find("OUDataInfo");
//        var $memberJson=[];
//        $childList.each(function (i, n) {
//        $memberJson.push({
//            "id": $(n).attr("GUID"),
//            "text": $(n).attr("Name"), 
//            "attributes":[{nodeType:$(n).attr("OUType")}],
//            "state":undefined
//        });
//        });
//        return $memberJson;
//}



//    $.fn.orgcombotree = function (options, param) {
//        //options = options || {};
//     if (typeof options == "string") {
//        return $.fn.orgcombotree.methods[options](this, param);
//    }
//    options = options || {};
//        return this.each(function () {
//         var opts;
//        var state= $(this).data("orgcombotree");
//        if (state) {
//            opts = $.extend(state, options);
//         } else {
//               opts = $.extend({}, options);
//                var multiple = $(this).attr("multiple");
//                var w=$(this).attr("width");
//                var includeMember= $(this).attr("includeMember");
//                 var codeJson =initOrg(includeMember);
//                if(multiple){
//                    $(this).combotree({
//                    multiple:true,
//                    width:w,
//                    cascadeCheck:true,
//                    editable:false
//                    });  
//                }else
//                { 
//                $(this).combotree({
//                    multiple:false,
//                     width:w,
//                    cascadeCheck:true,
//                    editable:false
//                    });  
//                }
//             $(this).combotree("loadData", codeJson);
//         }
//          $(this).data("orgcombotree",opts);
//        });
//    };
//})(jQuery);

/////attachlist
//(function($){

//function getFileList(dataGuid,dataType){
//    var $dataTemplate = $(utility.xml.convertXmlStringToDoc(PrjConstant.GLC.FeeMgr.FileInfoList.Template));
//    $dataTemplate.find("DataGuid").text(dataGuid);
//    $dataTemplate.find("DataType").text(dataType);

//    var codeDataText = dataService.transformData(PrjConstant.PrjTaskGuid.FeeMgr, utility.xml.convertXmlDocToString($dataTemplate));
//    var codeDataXml = utility.xml.convertXmlStringToDoc(codeDataText);
//    var codeList = codeDataXml.find("FileInfo");
//     return codeList;

//}
// $.fn.attachlist=function(options,param){
// if (typeof options == "string") {
//        return $.fn.attachlist.methods[options](this, param);
//    }
//    options = options || {};
//    return this.each(function () {
//        var opts;
//        var state= $(this).data("attachlist");
//        if (state) {
//            opts = $.extend(state, options);
//         } else {
//            opts = $.extend({}, options);
//            var attachListId=$(this).attr("id");
//            var codeList =getFileList(opts.DataGuid,opts.DataType);
//            var display=opts.Display;
//             var AttachmentGuid;
//               $.each(codeList, function (i, n) {
//                    AttachmentGuid = $(n).find("FileAttachmentGuid").text();
//                    var LocalFileName = $(n).find("LocalFileName").text();
//                    var FilePath = $(n).find("FilePath").text();
//                    if(display){
//                    $("#"+attachListId).append('<div id="attach'+ i + '" class="uploadifyQueueItem">\<a href="/Handler/FileDownloadHandler.ashx?filePath='+FilePath+'&&fileName='+LocalFileName+'"><span class="fileName">' + LocalFileName + '</span></a></div>');
//                    }else{
//                    $("#"+attachListId).append('<div id="attach'+ i + '" class="uploadifyQueueItem">\<div class="uploadify_cancel">\<a id="delBtn'+i+'" href="#"><img src="/images/uploadify_cancel.png" border="0" /></a>\</div>\<a href="/Handler/FileDownloadHandler.ashx?filePath='+FilePath+'&&fileName='+LocalFileName+'"><span class="fileName">' + LocalFileName + '</span></a></div>');
//                    $("#delBtn"+i).bind("click",function(){
//                     var result=dataService.delFile (AttachmentGuid,FilePath);
//                     if(result)
//                     {
//                     $("#"+attachListId).children("div[id='attach"+ i + "' ]").remove();
//                     }
//                     utility.message.promptOperationResult("删除", "【"+LocalFileName+"】", (result));
//                    });
//                    }
//                })
//        }
//        $(this).data("attachlist",opts);
//    });
// };
//})(jQuery);

////memberList
////(function ($) {


////function pushMember(branchGuid)
////{
////    var $childData = dataService.getData(SysConstant.TaskGuid.OrgInfo, branchGuid, Constant.Identify.BranchMemberList);
////    var $childXml = utility.xml.convertXmlStringToDoc($childData);
////    var $childList = $childXml.find("OUDataInfo");
////    var $memberJson=[];
////    $.each($childList,function(i,n){
////       $memberJson.push({
////        "id": $(n).attr("GUID"),
////        "text": deptInfo
////    });
////    });
////    return $memberJson;
////}
////    $.fn.membercombo = function (options, param) {
////        //options = options || {};
////        return this.each(function () {
////            $(this).combobox({
////            valueField:"id",
////            textField:'text' 
////            });
////        });
////    };
////})(jQuery);

//(function ($) {

//    function getFileList(dataGuid, dataType) {
//        var $dataTemplate = $(utility.xml.convertXmlStringToDoc(PrjConstant.GLC.FeeMgr.FileInfoList.Template));
//        $dataTemplate.find("DataGuid").text(dataGuid);
//        $dataTemplate.find("DataType").text(dataType);

//        var codeDataText = dataService.transformData(PrjConstant.PrjTaskGuid.FeeMgr, utility.xml.convertXmlDocToString($dataTemplate));
//        var codeDataXml = utility.xml.convertXmlStringToDoc(codeDataText);
//        var codeList = codeDataXml.find("FileInfo");
//        return codeList;

//    }
//    $.fn.attachlist = function (options, param) {
//        if (typeof options == "string") {
//            return $.fn.attachlist.methods[options](this, param);
//        }
//        options = options || {};
//        return this.each(function () {
//            var opts;
//            var state = $(this).data("attachlist");
//            if (state) {
//                opts = $.extend(state, options);
//            } else {
//                opts = $.extend({}, options);
//                var attachListId = $(this).attr("id");
//                var codeList = getFileList(opts.DataGuid, opts.DataType);
//                var display = opts.Display;
//                var AttachmentGuid;
//                $.each(codeList, function (i, n) {
//                    AttachmentGuid = $(n).find("FileAttachmentGuid").text();
//                    var LocalFileName = $(n).find("LocalFileName").text();
//                    var FilePath = $(n).find("FilePath").text();
//                    if (display) {
//                        $("#" + attachListId).append('<div id="attach' + i + '" class="uploadifyQueueItem">\<a href="/Handler/FileDownloadHandler.ashx?filePath=' + FilePath + '&&fileName=' + LocalFileName + '"><span class="fileName">' + LocalFileName + '</span></a></div>');
//                    } else {
//                        $("#" + attachListId).append('<div id="attach' + i + '" class="uploadifyQueueItem">\<div class="uploadify_cancel">\<a id="delBtn' + i + '" href="#"><img src="/images/uploadify_cancel.png" border="0" /></a>\</div>\<a href="/Handler/FileDownloadHandler.ashx?filePath=' + FilePath + '&&fileName=' + LocalFileName + '"><span class="fileName">' + LocalFileName + '</span></a></div>');
//                        $("#delBtn" + i).bind("click", function () {
//                            var result = dataService.delFile(AttachmentGuid, FilePath);
//                            if (result) {
//                                $("#" + attachListId).children("div[id='attach" + i + "' ]").remove();
//                            }
//                            utility.message.promptOperationResult("删除", "【" + LocalFileName + "】", (result));
//                        });
//                    }
//                })
//            }
//            $(this).data("attachlist", opts);
//        });
//    };
//})(jQuery);=======
﻿(function ($) {
    // formpanel
    function getPanelId(buttonId) {
        return buttonId.split("_")[0];
    }

    function getPanelInputWithXmlString(panelId, xmlTemplate) {
        var xml = $(utility.xml.convertXmlStringToDoc(xmlTemplate));
        var xml = utility.xml.convertTableHtmlToXml(panelId, xml);
        return xml;
    }

    function setPanelInputWithXmlString(panelId, xmlTemplate) {
        var xml = $(utility.xml.convertXmlStringToDoc(xmlTemplate));
        //alert("fill data for " + panelId);
        utility.xml.convertXmlToTableHtml(xml, panelId);
        //alert("complete fill data for " + panelId);
    }

    function setGuidInputValue(inputControl, newValue) {
        utility.control.setInputValue(inputControl, newValue);
    }

    function getDataXmlString(taskGuid, dataType, dataGuid) {
        var result = dataService.getData(taskGuid, dataGuid, dataType);
        return result;
    }

    function getDataXmlDom(taskGuid, dataType, dataGuid) {
        var xmlStr = getDataXmlString(taskGuid, dataType, dataGuid);
        return $(utility.xml.convertXmlStringToDoc(xmlStr));
    }

    function executeSubmit() {
        //alert("submit");
        var panelId = getPanelId(this.id);
        var inputValidated = true;
        var inputForm = $('#' + panelId).find("form");
        if (inputForm)
            inputValidated = inputForm.form('validate');
        if (inputValidated) {
            var opts = $('#' + panelId).data("formpanel");
            var template = opts["formTemplate"];
            //var guidInput = opts["dataGuidInput"];
            var guidNode = opts.guidNode;
            var dataType = opts["dataType"];
            //var dataGuid = $(guidInput).val();
            //var dataGuid = $(guidNode).text();
            var xmlPara = getPanelInputWithXmlString("#" + panelId, template);
            var dataGuid = xmlPara.find(guidNode).text();
            xmlPara.find("Document").attr("DataGuid", dataGuid);
            result = dataService.setData(opts.taskGuid, dataGuid, dataType, utility.xml.convertXmlDocToString(xmlPara));
            opts.onExecuteComplete(result);
        }
        return false;
    }

    function executeCancel() {
        var panelId = getPanelId(this.id);
        //alert("cancel " + panelId);
        var opts = $('#' + panelId).data("formpanel");
        switch (opts.formStyle) {
            case "window":
                utility.page.closeTab();
                break;
            case "dialog":
                utility.page.closeDialog();
                break;
        }
    }

    function executeQuery() {
        //alert("query");
        var panelId = getPanelId(this.id);
        var inputValidated = true;
        var inputForm = $('#' + panelId).find("form");
        if (inputForm)
            inputValidated = inputForm.form('validate');
        if (inputValidated) {
            var opts = $('#' + panelId).data("formpanel");
            var template = opts["formTemplate"];
            var xmlPara = getPanelInputWithXmlString("#" + panelId, template);
            //result = utility.xml.convertXmlStringToDoc(dataService.transformData(opts.taskGuid, utility.xml.convertXmlDocToString(xmlPara)));
            result = dataService.transformData(opts.taskGuid, utility.xml.convertXmlDocToString(xmlPara));
            opts.onExecuteComplete(result);
            resizePanel("#" + panelId);
        }
        return false;
    }

    function executeReset() {
        var panelId = getPanelId(this.id);
        //alert(tableId);
        utility.control.resetInput("#" + panelId);
    }

    function resizePanel(target) {
        $(target).panel("panel").triggerHandler("_resize");
    }

    $.fn.formpanel = function (options, param) {
        if (typeof options == "string") {
            return $.fn.formpanel.methods[options](this, param);
        }

        options = options || {};
        return this.each(function () {
            var panelId = this.id;
            var state = $(this).data("formpanel");
            var buttonDivStyle = "";
            var opts;
            if (state) {
                opts = $.extend(state.options, options);
            } else {
                var customOptions = $.fn.formpanel.parseOptions(this);
                var formType = customOptions["formType"];
                if (formType == undefined) { return false; }

                var actionCode = "";
                var dataGuid = "";
                //$(this).attr("title",opts.queryButtonText);
                switch (formType) {
                    case "query":
                        opts = $.extend({}, $.fn.formpanel.defaults, $.fn.formpanel.defaults.query, customOptions, options);
                        break;
                    case "edit":
                        //alert("edit " + dataGuid);
                        opts = $.extend({}, $.fn.formpanel.defaults, $.fn.formpanel.defaults.edit, customOptions, options);
                        if (opts.formStyle == "dialog") {
                            var editPara = $.fn.szjt_popupDialog("editParameter");
                            actionCode = editPara.actionCode;
                            dataGuid = editPara.selectedList;
                        } else {
                            actionCode = opts.actionCode;
                            dataGuid = opts.dataGuid;
                        }
                        var guidNode = opts.guidNode;
                        var xmlDom = getDataXmlDom(opts.taskGuid, opts.dataType, (dataGuid != "" && dataGuid != undefined ? dataGuid : "1"));
                        if (!dataGuid || dataGuid == "" || actionCode == "copy") {
                            var newGuid = dataService.getNewGuid();
                            setGuidInputValue(opts.guidInput, newGuid);
                            xmlDom.find(guidNode).text(newGuid);
                        }
                        //                        if (opts.formStyle == "dialog") {
                        //                            $.parser.onComplete = function () { setPanelInputWithXmlString("#" + panelId, utility.xml.convertXmlDocToString(xmlDom)); };
                        //                        } else {
                        //                            setPanelInputWithXmlString("#" + panelId, utility.xml.convertXmlDocToString(xmlDom));
                        //                        }
                        setPanelInputWithXmlString("#" + panelId, utility.xml.convertXmlDocToString(xmlDom));
                        break;
                    case "display":
                        //alert("edit " + dataGuid);
                        opts = $.extend({}, $.fn.formpanel.defaults, $.fn.formpanel.defaults.display, customOptions, options);
                        var dataGuid = opts.dataGuid;
                        var guidNode = opts.guidNode;
                        if (dataGuid) {
                            var xmlDom = getDataXmlDom(opts.taskGuid, opts.dataType, (dataGuid != "" ? dataGuid : "1"));
                            //$.parser.onComplete = function () { 
                            setPanelInputWithXmlString("#" + panelId, utility.xml.convertXmlDocToString(xmlDom));
                            // };
                        }
                        break;
                }
                switch (opts.formStyle) {
                    case undefined, "window":
                        buttonDivStyle = "width:90%;left:5%;text-align:center;";
                        break;
                    case "dialog":
                        buttonDivStyle = "position:relative;width:90%;left:5%;bottom:10px;margin-left:0px;text-align:center;";
                        break;
                }
                $(this).data("formpanel", opts);
                if (buttonDivStyle.length > 0) {
                    $(this).prepend("<form id=\"form_" + panelId + "\" method=\"post\">");
                    $(this).append('<div id="' + panelId + '_formButtons" style=\"' + buttonDivStyle + '\">' +
                    '<a id="' + panelId + '_executeButton"></a>' +
                    '　　　　　　　　' +
                    '<a id="' + panelId + '_restoreButton"></a>' +
                    '</div>');
                    $(this).append("</form>");
                    $("#" + panelId + "_executeButton").linkbutton({ text: opts.executeButtonText, iconCls: opts.executeButtonIcon });
                    //var queryButton = $("#" + panelId + "_buttonQuery");
                    //queryButton.click = executeQuery(this.id);
                    $("#" + panelId + "_executeButton").bind("click", opts.onExecute);
                    $("#" + panelId + "_restoreButton").linkbutton({ text: opts.restoreButtonText, iconCls: opts.restoreButtonIcon });
                    $("#" + panelId + "_restoreButton").bind("click", opts.onRestore);
                    $(this).bind("_execute", opts.onExecute);
                    $(this).bind("_restore", opts.onRestore);
                }
            }
            $(this).panel(opts);
            //$(this).bind("_resize", function () { alert("my resize"); });
        });
    };

    $.fn.formpanel.defaults = {
        width: 'auto',
        height: 'auto',
        left: null,
        top: null,
        content: null,
        onCollapse: function () { resizePanel(this); },
        onExpand: function () { resizePanel(this); },

        // below are extended attribs or functions
        fitwidth: true,
        formTemplate: '',
        taskGuid: '',
        dataType: '',
        dataGuid: undefined,
        dataGuidInput: '',
        onExecuteComplete: function (executeResult) { }
    };

    $.fn.formpanel.defaults.display = {
        formStyle: '',
        title: '',
        iconCls: '',
        collapsible: false,
        collapsed: false
    };

    $.fn.formpanel.defaults.query = {
        formStyle: "window",
        title: '查询条件',
        iconCls: 'icon-search',
        collapsible: true,
        collapsed: false,
        executeButtonText: '查 询',
        restoreButtonText: '重 置',
        executeButtonIcon: 'icon-search',
        restoreButtonIcon: 'icon-reload',
        onExecute: executeQuery,
        onRestore: executeReset
    };

    $.fn.formpanel.defaults.edit = {
        formStyle: "dialog",
        title: '',
        iconCls: '',
        collapsible: false,
        collapsed: false,
        border: false,
        executeButtonText: '提 交',
        restoreButtonText: '取 消',
        executeButtonIcon: 'icon-ok',
        restoreButtonIcon: 'icon-cancel',
        closeAfterSubmit: true,
        onExecute: executeSubmit,
        onRestore: executeCancel
    };

    $.fn.formpanel.parseOptions = function (target) {
        var t = $(target);
        return $.extend({}, $.fn.datagrid.parseOptions(target), {
            formType: (t.attr("formType") || undefined),
            formStyle: (t.attr("formStyle") || undefined),
            formTemplate: (t.attr("formTemplate") || undefined),
            executeButtonText: (t.attr("executeButtonText") || undefined),
            restoreButtonText: (t.attr("restoreButtonText") || undefined),
            executeButtonIcon: (t.attr("executeButtonIcon") || undefined),
            restoreButtonIcon: (t.attr("restoreButtonIcon") || undefined),
            formTemplate: (t.attr("formTemplate") || undefined),
            dataGuidInput: (t.attr("dataGuidInput") || undefined),
            dataType: (t.attr("dataType") || undefined),
            dataGuid: (t.attr("dataGuid") || undefined)
        });
    };


    $.fn.formpanel.methods = {
        formTemplate: function () { return queryXmlTemplate; }
    };
})(jQuery);

(function ($) {
    $.fn.edittable = function (options, param) {
        var attrMandatory;
        options = options || {};
        return this.each(function () {
            //debugger;
            $(this).find("td:even").each(function (i, n) {
                n.align = "right";
                attrMandatory = $(n).attr("required");
                if (attrMandatory != undefined) {
                    $(n).append("<span style='color:red'>*</span>");
                }
                //$(n).append("：");
                $(n).css({ "background-color": "#F5F5F8","font-weight": "bold","width":"150px" });
            });
            $(this).find("td:odd").each(function (i, n) {
                    n.align = "left";
            });
            $(this).css({"border-width": "1px"});
            if( $(this).attr("enabled") == "false"){
                $(this).find("input,select").each(function(i,n) {
                    $(n).attr("disabled", true);
                });
            }
        });
    };
})(jQuery);

///codecombo
(function ($) {
    $.fn.codecombo = function (options, param) {
        options = options || {};
        return this.each(function () {
            var codeCategory = $(this).attr("category")?$(this).attr("category"):options.category;
            if(codeCategory != undefined){
                var codeStatus = "0"; //$(this).attr("status") || "0";
                //var codeSearchTemp = Constant.SysTemplate.UsrIntr.CodeTableList.replace("{0}", codeCategory).replace("{1}", codeStatus);
                var parentGuid = "";
                var includeSubCode = false;
                var codeSearchTemp = Constant.SysTemplate.UsrIntr.SysCodeList.replace("{0}", codeCategory).replace("{1}", parentGuid).replace("{2}", includeSubCode);
                var codeDataText = dataService.transformData(SysConstant.TaskGuid.ExtComponent, codeSearchTemp);
                var codeDataXml = utility.xml.convertXmlStringToDoc(codeDataText);
                var codeList = codeDataXml.find("SubCode");
                var codeJson = [{"id":"","text":"--请选择--","selected":true}];
                codeList.each(function (i, n) {
                    codeJson.push({ "id": $(n).find("CodeName").text(), "text": $(n).find("CodeValue").text() });
                });
                if($(this).attr("dropdownstyle")=="DropDownList"){
                    $(this).combo({
                        valueField:"id",
                        textField:"text"
                    });
                    $(this).combo("setValues", codeJson);
                }else{
                    $(this).combobox({
                        valueField:"id",
                        textField:"text"
                    });
                    $(this).combobox("loadData", codeJson);
                }
            }
        });
    };
})(jQuery);

///codeMulticombo
(function ($) { 
function codeMultiComboChange(target,rowData){
         var opts = $(target).data("codeMulticombo");
        if(opts.onTextChange){
            opts.onTextChange.call($(target),rowData.text,rowData.name);
        }
}

$.fn.codeMulticombo=function(options,param){
        if (typeof options == "string") {
            return $.fn.codeMulticombo.methods[options](this, param);
        }
  options = options || {};
  return this.each(function () {
            var opts;
            var state= $(this).data("codeMulticombo");
            if (state) {
                opts = $.extend(state.options, options);
            } else
            {
            var $parentCombo=$(this);
            opts = $.extend({},$.fn.codeMulticombo.defaults, options);
           
            var codeCategory = $(this).attr("category");
            var codeMuti=$(this).attr("multiple");
            if(codeCategory != undefined){
             
                var codeStatus = "0"; //$(this).attr("status") || "0";
                //var codeSearchTemp = Constant.SysTemplate.UsrIntr.CodeTableList.replace("{0}", codeCategory).replace("{1}", codeStatus);
                var parentGuid = "";
                var includeSubCode = false;
                var codeJson =getChildrenNodeData(codeCategory,"",true);
                var codeTreeID=$(this).attr("id")+"_codetree";
                if ($("#"+codeTreeID) != undefined && $("#"+codeTreeID).length!=0) {
                $("#"+codeTreeID).empty();
                $("#"+codeTreeID).remove();
                }
                $(this).combo({});
                $(this).combo("panel").panel({
                width:400,
                content:"<table id='"+codeTreeID+"'></table>"
                });
                $("#"+codeTreeID).treegrid({
                idField: "id",
                treeField: "text",
                height:$parentCombo.combo("options").panelHeight,
                rownumbers: true,
                frozenColumns: [[
                    {title:'编号',field:'text',width:150}
				]],
                fitColumns:true,
                columns:[[{title:'名称',field:'name',width:200} ]],
                singleSelect:true,
                onClickRow: function (rowData) {
                  $parentCombo.combo("setValue",rowData.text);   
                  $parentCombo.combo("setText",rowData.name); 
                  codeMultiComboChange($parentCombo,rowData);
                },
               onDblClickRow:function(rowData){
                $parentCombo.combo("setValue",rowData.text);   
                $parentCombo.combo("setText",rowData.name);  
                $parentCombo.combo("hidePanel");
                codeMultiComboChange($parentCombo,rowData);
               }
            });
                $("#"+codeTreeID).treegrid("loadData",codeJson);
            }
            }
           $(this).data("codeMulticombo",opts);
        });
};

 $.fn.codeMulticombo.parseOptions = function (target) {
        var t = $(target);
        return $.extend({},{},$.fn.validatebox.parseOptions(target), $.fn.combo.parseOptions(target), {
            category: (t.attr("category") || undefined)
        });
    };

$.fn.codeMulticombo.defaults=$.extend({},$.fn.validatebox.defaults,$.fn.combo.defaults,{
onTextChange:function(newValue,newText){}
});

$.fn.codeMulticombo.methods = {
        setValue: function () { return queryXmlTemplate; }
    };
})(jQuery);

///toolbar
(function ($) { 
    $.fn.toolbar = function(options){
        if (typeof options == "string") {
            $(options).addClass("datagrid-toolbar").prependTo(this);
            $(options).show();
        }else{
            return this.each(function () {
//                $("div.datagrid-toolbar",this).remove();
                var tb=$("<div class=\"datagrid-toolbar\"></div>").prependTo(this);
                for(var i=0;i<options.length;i++){
                    var btn=options[i];
                    if(btn=="-"){
                        $("<div class=\"datagrid-btn-separator\"></div>").appendTo(tb);
                    }else{
                        var tool=$("<a href=\"javascript:void(0)\"></a>");
                        tool[0].onclick=eval(btn.handler||function(){});
                        tool.css("float","left").appendTo(tb).linkbutton($.extend({},btn,{plain:true}));
                    }
                }
            });
        }
    };
})(jQuery);

///branchcombo
(function ($) { 
    function getBranchBindValueFieldName(target){
        var opts = $(target).data("branchcombo");
        if(opts){
            return opts.bindValueField;
        }else{
            return undefined;
        }
    }

    function showRowData(target, rowData){
        target.combo("setValue",rowData.id);
        target.combo("setText",rowData.name);
        branchTextChange(target, rowData);
    }

    function branchTextChange(target, rowData ){
        var opts = $(target).data("branchcombo");
        if(opts.onTextChange){
            opts.onTextChange.call(target,rowData.name);
        }
        if(opts.onValueChange){
         opts.onValueChange.call(target,rowData.id);
        }
    }

$.fn.branchcombo=function(options,param){
    if (typeof options == "string") {
        return $.fn.branchcombo.methods[options](this, param);
    }
    options = options || {};
    return this.each(function () {
        var opts;
        var state= $(this).data("branchcombo");
        if (state) {
            opts = $.extend(state, options);
         } else {
            var parentCombo=$(this);
            opts = $.extend({},$.fn.branchcombo.defaults, $.fn.branchcombo.parseOptions(this), options);
            var codeJson =initDepart();
            var codeTreeID=$(this).attr("id")+"_departtree";
            if ($("#"+codeTreeID) != undefined && $("#"+codeTreeID).length!=0) {
                $("#"+codeTreeID).empty();
                $("#"+codeTreeID).remove();
            }
             $(this).combo({editable:false});//禁用手工输入
            $(this).combo("panel").panel({
                width:400,
                content:"<table id='"+codeTreeID+"'></table>"
            });
            
            var codetreegrid= $("#"+codeTreeID);
            codetreegrid.treegrid({
                idField: "id",
                treeField: "code",
                height: parentCombo.combo("options").panelHeight,
                rownumbers: true,
                columns: [[
                    { field: "id", title: 'id', hidden: true },
                    { field: 'code', title: "部门编号", width: 200 },
                    { field: "name", title: "部门名称", width: 300 }
                ]],
                fitColumns:true,
                singleSelect:true,
                onClickRow: function (rowData) {
                    showRowData(parentCombo, rowData);
                },
                onDblClickRow:function(rowData){
                    showRowData(parentCombo, rowData);
                    parentCombo.combo("hidePanel");
                }
            });
            codetreegrid.treegrid("loadData",codeJson);
            opts.treegrid = codetreegrid;
        }
        if(opts.bindValueField)
        {
            if(opts.bindValueField!="" && opts.bindValueField.substring(0,1)!="#"){
                opts.bindValueField = "#"+ opts.bindValueField;
            }
        }
        $(this).data("branchcombo",opts);
    });
};
    $.fn.branchcombo.defaults=$.extend({},$.fn.validatebox.defaults,
    {bindValueField: "",onTextChange: function(newText){
            var valueField = getBranchBindValueFieldName(this);
            if(valueField) {
                $(valueField).val(newText);
            }
        },
        onValueChange:function(newValue){
        
        }
        });

    $.fn.branchcombo.parseOptions = function (target) {
        var t = $(target);
        return $.extend({},{},$.fn.validatebox.parseOptions(target), $.fn.combo.parseOptions(target), {
            bindValueField: (t.attr("bindValueField") || undefined)
        });
    };

    $.fn.branchcombo.methods = {
        setValue: function () { return null; },
        getBindField: function(jq){ return getBranchBindValueFieldName(jq);},
        treegrid:function(jq){
            return $(jq[0]).data("branchcombo").treegrid;
        },
        getRoot:function(jq,nodeid){
            var treegrid = $(jq).branchcombo("treegrid");
            var rootNode = treegrid.treegrid("getParent", nodeid);
            var rootNode1 = null;
            while (rootNode != null) {
                rootNode1 = rootNode;
                rootNode = treegrid.treegrid("getParent", rootNode.id);
            }
            return rootNode1;
        }
    };
})(jQuery);

///orgcombotree
(function ($) {
function initOrg(includeMember){
    var $data = dataService.getData(SysConstant.TaskGuid.OrgInfo, Constant.SysDataGuid.OrgInfo.CompanyListGuid, Constant.Identify.CompanyList);
    var $xml = utility.xml.convertXmlStringToDoc($data);
    var $list=$xml.find("OUDataInfo");
//    var orgList=[];
//    $.each($list,function(i,n){
//    var $comlist = $xml.find("OUDataInfo");
//    })
//    

    return pushChildList($list,includeMember);
}
function pushChildList($list,includeMember) {
    var $departJson = [];
    if (!$list.length > 0)
        return;
    $list.each(function (i, n) {
        var $childData = dataService.getData(SysConstant.TaskGuid.OrgInfo, $(n).attr("GUID"), Constant.Identify.BranchList);
        var $childXml = utility.xml.convertXmlStringToDoc($childData);
        var $childList = $childXml.find("OUDataInfo");
        var deptInfo = $(n).attr("Name");
        $departJson.push({
            "id": $(n).attr("GUID"),
            "text": deptInfo, 
            "attributes":[{nodeType: $(n).attr("OUType")}],
            "state": $childList.length > 0 ? "closed" : undefined,
            "children": $childList.length > 0 ? pushChildList($childList,includeMember) : includeMember?pushMember($(n).attr("GUID")):undefined
        });
    });
    return $departJson;
}

function pushMember(branchGuid)
{
        var $childData = dataService.getData(SysConstant.TaskGuid.OrgInfo, branchGuid, Constant.Identify.BranchMemberList);
        var $childXml = utility.xml.convertXmlStringToDoc($childData);
        var $childList = $childXml.find("OUDataInfo");
        var $memberJson=[];
        $childList.each(function (i, n) {
        $memberJson.push({
            "id": $(n).attr("GUID"),
            "text": $(n).attr("Name"), 
            "attributes":[{nodeType:$(n).attr("OUType")}],
            "state":undefined
        });
        });
        return $memberJson;
}



    $.fn.orgcombotree = function (options, param) {
        //options = options || {};
     if (typeof options == "string") {
        return $.fn.orgcombotree.methods[options](this, param);
    }
    options = options || {};
        return this.each(function () {
         var opts;
        var state= $(this).data("orgcombotree");
        if (state) {
            opts = $.extend(state, options);
         } else {
               opts = $.extend({}, options);
                var multiple = $(this).attr("multiple");
                var w=$(this).attr("width");
                var includeMember= $(this).attr("includeMember");
                 var codeJson =initOrg(includeMember);
                if(multiple){
                    $(this).combotree({
                    multiple:true,
                    width:w,
                    cascadeCheck:true,
                    editable:false
                    });  
                }else
                { 
                $(this).combotree({
                    multiple:false,
                     width:w,
                    cascadeCheck:true,
                    editable:false
                    });  
                }
             $(this).combotree("loadData", codeJson);
         }
          $(this).data("orgcombotree",opts);
        });
    };
})(jQuery);

///attachlist
(function($){

function getFileList(dataGuid,dataType){
    var $dataTemplate = $(utility.xml.convertXmlStringToDoc(PrjConstant.GLC.FeeMgr.FileInfoList.Template));
    $dataTemplate.find("DataGuid").text(dataGuid);
    $dataTemplate.find("DataType").text(dataType);

    var codeDataText = dataService.transformData(PrjConstant.PrjTaskGuid.FeeMgr, utility.xml.convertXmlDocToString($dataTemplate));
    var codeDataXml = utility.xml.convertXmlStringToDoc(codeDataText);
    var codeList = codeDataXml.find("FileInfo");
     return codeList;

}
 $.fn.attachlist=function(options,param){
 if (typeof options == "string") {
        return $.fn.attachlist.methods[options](this, param);
    }
    options = options || {};
    return this.each(function () {
        var opts;
        var state= $(this).data("attachlist");
        if (state) {
            opts = $.extend(state, options);
         } else {
            opts = $.extend({}, options);
            var attachListId=$(this).attr("id");
            var codeList =getFileList(opts.DataGuid,opts.DataType);
            var display=opts.Display;
             var AttachmentGuid;
               $.each(codeList, function (i, n) {
                    AttachmentGuid = $(n).find("FileAttachmentGuid").text();
                    var LocalFileName = $(n).find("LocalFileName").text();
                    var FilePath = $(n).find("FilePath").text();
                    if(display){
                    $("#"+attachListId).append('<div id="attach'+ i + '" class="uploadifyQueueItem">\<a href="/Handler/FileDownloadHandler.ashx?filePath='+FilePath+'&&fileName='+LocalFileName+'"><span class="fileName">' + LocalFileName + '</span></a></div>');
                    }else{
                    $("#"+attachListId).append('<div id="attach'+ i + '" class="uploadifyQueueItem">\<div class="uploadify_cancel">\<a id="delBtn'+i+'" href="#"><img src="/images/uploadify_cancel.png" border="0" /></a>\</div>\<a href="/Handler/FileDownloadHandler.ashx?filePath='+FilePath+'&&fileName='+LocalFileName+'"><span class="fileName">' + LocalFileName + '</span></a></div>');
                    $("#delBtn"+i).bind("click",function(){
                     var result=dataService.delFile (AttachmentGuid,FilePath);
                     if(result)
                     {
                     $("#"+attachListId).children("div[id='attach"+ i + "' ]").remove();
                     }
                     utility.message.promptOperationResult("删除", "【"+LocalFileName+"】", (result));
                    });
                    }
                })
        }
        $(this).data("attachlist",opts);
    });
 };
})(jQuery);

//memberList
//(function ($) {


//function pushMember(branchGuid)
//{
//    var $childData = dataService.getData(SysConstant.TaskGuid.OrgInfo, branchGuid, Constant.Identify.BranchMemberList);
//    var $childXml = utility.xml.convertXmlStringToDoc($childData);
//    var $childList = $childXml.find("OUDataInfo");
//    var $memberJson=[];
//    $.each($childList,function(i,n){
//       $memberJson.push({
//        "id": $(n).attr("GUID"),
//        "text": deptInfo
//    });
//    });
//    return $memberJson;
//}
//    $.fn.membercombo = function (options, param) {
//        //options = options || {};
//        return this.each(function () {
//            $(this).combobox({
//            valueField:"id",
//            textField:'text' 
//            });
//        });
//    };
//})(jQuery);

(function ($) {

    function getFileList(dataGuid, dataType) {
        var $dataTemplate = $(utility.xml.convertXmlStringToDoc(PrjConstant.GLC.FeeMgr.FileInfoList.Template));
        $dataTemplate.find("DataGuid").text(dataGuid);
        $dataTemplate.find("DataType").text(dataType);

        var codeDataText = dataService.transformData(PrjConstant.PrjTaskGuid.FeeMgr, utility.xml.convertXmlDocToString($dataTemplate));
        var codeDataXml = utility.xml.convertXmlStringToDoc(codeDataText);
        var codeList = codeDataXml.find("FileInfo");
        return codeList;

    }
    $.fn.attachlist = function (options, param) {
        if (typeof options == "string") {
            return $.fn.attachlist.methods[options](this, param);
        }
        options = options || {};
        return this.each(function () {
            var opts;
            var state = $(this).data("attachlist");
            if (state) {
                opts = $.extend(state, options);
            } else {
                opts = $.extend({}, options);
                var attachListId = $(this).attr("id");
                var codeList = getFileList(opts.DataGuid, opts.DataType);
                var display = opts.Display;
                var AttachmentGuid;
                $.each(codeList, function (i, n) {
                    AttachmentGuid = $(n).find("FileAttachmentGuid").text();
                    var LocalFileName = $(n).find("LocalFileName").text();
                    var FilePath = $(n).find("FilePath").text();
                    if (display) {
                        $("#" + attachListId).append('<div id="attach' + i + '" class="uploadifyQueueItem">\<a href="/Handler/FileDownloadHandler.ashx?filePath=' + FilePath + '&&fileName=' + LocalFileName + '"><span class="fileName">' + LocalFileName + '</span></a></div>');
                    } else {
                        $("#" + attachListId).append('<div id="attach' + i + '" class="uploadifyQueueItem">\<div class="uploadify_cancel">\<a id="delBtn' + i + '" href="#"><img src="/images/uploadify_cancel.png" border="0" /></a>\</div>\<a href="/Handler/FileDownloadHandler.ashx?filePath=' + FilePath + '&&fileName=' + LocalFileName + '"><span class="fileName">' + LocalFileName + '</span></a></div>');
                        $("#delBtn" + i).bind("click", function () {
                            var result = dataService.delFile(AttachmentGuid, FilePath);
                            if (result) {
                                $("#" + attachListId).children("div[id='attach" + i + "' ]").remove();
                            }
                            utility.message.promptOperationResult("删除", "【" + LocalFileName + "】", (result));
                        });
                    }
                })
            }
            $(this).data("attachlist", opts);
        });
    };
})(jQuery);>>>>>>> .r14713
